package com.example.thread;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName: StopThread
 * @Description:
 * @Author:
 * @Date
 */
public class StopThread {

    /**
     * 线程暂停 suspend方法
     *  如果线程持有锁，线程暂停后，锁不会主动进行释放，会一直继续由暂停的线程持有住。
     *
     * */
    static class SuspendThread implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 10000; i++) {
                System.out.print(i+" ");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
//        Thread suspendThread = new Thread(new SuspendThread());
//        suspendThread.start();
//        TimeUnit.SECONDS.sleep(5);
//        System.out.print("线程暂停");
//        //暂停线程
//        suspendThread.suspend();
//        TimeUnit.SECONDS.sleep(2);
//        //从之前暂停的位置恢复继续执行
//        suspendThread.resume();
//        System.out.print(" 线程恢复");

    }
}
//
//
//
//    ObjectMonitor() {
//        _header       = NULL;
//        _count        = 0;
//        _waiters      = 0,
//                _recursions   = 0;
//        _object       = NULL;
//        _owner        = NULL; //这是指持有当前 objectMonitor 的线程(通常每个线程对应一个 objectMonitor)
//        _WaitSet      = NULL;  //进入到 wait 状态的线程队列
//        _WaitSetLock  = 0 ;
//        _Responsible  = NULL ;
//        _succ         = NULL ;
//        _cxq          = NULL ;
//        FreeNext      = NULL ;
//        _EntryList    = NULL ;  //进入等待 monitor 的线程队列
//        _SpinFreq     = 0 ;
//        _SpinClock    = 0 ;
//        OwnerIsThread = 0 ;
//    }
//
//private:
//protected:
//        ObjectWaiter * volatile _WaitSet; // LL of threads wait()ing on the monitor
//
//protected:
//        ObjectWaiter * volatile _EntryList ;     // Threads blocked on entry or reentry.
//
//
//protected:                         // protected for jvmtiRawMonitor
//        void *  volatile _owner;          // pointer to owning thread OR BasicLock
//
//三个对象，一个是watiSet, 一个是entryList,  一个是onwer
//
//
////双向链表结构
//class ObjectWaiter : public StackObj {
//public:
//enum TStates { TS_UNDEF, TS_READY, TS_RUN, TS_WAIT, TS_ENTER, TS_CXQ } ;
//enum Sorted  { PREPEND, APPEND, SORTED } ;
//  ObjectWaiter * volatile _next; //前指针
//        ObjectWaiter * volatile _prev; //后指针
//        Thread*       _thread;  //当前线程
//        jlong         _notifier_tid;
//        ParkEvent *   _event;
//volatile int  _notified ;
//volatile TStates TState ;
//        Sorted        _Sorted ;           // List placement disposition
//        bool          _active ;           // Contention monitoring is enabled
//public:
//        ObjectWaiter(Thread* thread);
//
//        void wait_reenter_begin(ObjectMonitor *mon);
//        void wait_reenter_end(ObjectMonitor *mon);
//        };